package Testwork;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

class User implements Comparable<User> {
	private int age;

	public User(int age) {
		this.age = age;
	}

	public int getAge() {
		return age;
	}

	@Override
	public int compareTo(User o) {

		return age - o.age;
	}

	@Override
	public String toString() {
		return "User [age=" + age + "]";
	}

}

class StuUser extends User {
	private String no;

	public StuUser(int age, String no) {
		super(age);
		this.no = no;
	}

	public String getNo() {
		return no;
	}

	@Override
	public String toString() {
		return "StuUser [no=" + no + ", toString()=" + super.toString() + "]";
	}

}

class UserReverseComparator implements Comparator<User> {

	@Override
	public int compare(User o1, User o2) {
		return o2.getAge() - o1.getAge();
	}

}

class StuUserComparator implements Comparator<StuUser> {

	@Override
	public int compare(StuUser o1, StuUser o2) {
		return o1.getNo().compareTo(o2.getNo());
	}

}

public class GenericMain {
//	public static <T extends Comparable<? super T>> T max(List<T> list, Comparator<? super T> c){
//		Collections.sort(list,c);
//		return list.get(list.size()-1);
//	}
	public static <T extends User> int mycompare(T o1,T o2, Comparator<? super T> c){
		return c.compare(o1, o2);
	}
	public static void main(String[] args) {
		StuUser s1=new StuUser(12,"008");
		StuUser s2=new StuUser(19,"110");
		User u1=new User(20);
		int x1=mycompare(s1,s2,new StuUserComparator());
		int x2=mycompare(s1,u1,new UserReverseComparator());
		if(x1>0){
			System.out.println("s1.no>s2.no>");
		}else{
			System.out.println("s1.no<=s2.no>");
		}
		if(x2<0){
			System.out.println("s1.age>u1.age>");
		}else{
			System.out.println("s1.age<=u1.age>");
		}
//		StuUser[] s=new StuUser[3];
//		s[0]=new StuUser(12,"008");
//		s[1]=new StuUser(19,"110");
//		s[2]=new StuUser(13,"999");
//		List<StuUser> list=new ArrayList<StuUser>();
//		list.add(s[0]);
//		list.add(s[1]);
//		list.add(s[2]);
//		list.add("banana");
//		list.add("apple");
//		list.add("pineapple");
//		System.out.println(max(list,new StuUserComparator()));
//		System.out.println(max(list,new UserReverseComparator()));
	}
}


